package com.hezhi.project.module.recipient.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.hezhi.project.module.recipient.domain.Recipient;
import com.hezhi.project.module.recipient.service.IRecipientService;
import com.hezhi.framework.web.controller.BaseController;
import com.hezhi.framework.web.page.TableDataInfo;
import com.hezhi.framework.web.domain.AjaxResult;

/**
 * 通知消息接收 信息操作处理
 * 
 * @author hezhi
 * @date 2018-08-13
 */
@Controller
@RequestMapping("/module/recipient")
public class RecipientController extends BaseController
{
    private String prefix = "module/recipient";
	
	@Autowired
	private IRecipientService recipientService;
	
	@RequiresPermissions("module:recipient:view")
	@GetMapping()
	public String recipient()
	{
	    return prefix + "/recipient";
	}
	
	/**
	 * 查询通知消息接收列表
	 */
	@RequiresPermissions("module:recipient:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(Recipient recipient)
	{
		startPage();
        List<Recipient> list = recipientService.selectRecipientList(recipient);
		return getDataTable(list);
	}
	
	/**
	 * 新增通知消息接收
	 */
	@RequiresPermissions("module:recipient:add")
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}

	/**
	 * 修改通知消息接收
	 */
	@RequiresPermissions("module:recipient:edit")
	@GetMapping("/edit/{noticeId}")
	public String edit(@PathVariable("noticeId") Integer noticeId, Model model)
	{
		Recipient recipient = recipientService.selectRecipientById(noticeId);
		model.addAttribute("recipient", recipient);
	    return prefix + "/edit";
	}
	
	/**
	 * 保存通知消息接收
	 */
	@RequiresPermissions("module:recipient:save")
	@PostMapping("/save")
	@ResponseBody
	public AjaxResult save(Recipient recipient)
	{
		if (recipientService.saveRecipient(recipient) > 0)
		{
			return success();
		}
		return error();
	}
	
	/**
	 * 删除通知消息接收
	 */
	@RequiresPermissions("module:recipient:remove")
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{
		int rows = recipientService.deleteRecipientByIds(ids);
		if (rows > 0)
        {
            return success();
        }
        return error();
	}
	
}
